package org.iteam.xlz.manager.action.order;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.iteam.web.shiro.ShiroUtil;
import org.iteam.web.struts.action.AbstractModuleAction;
import org.iteam.xlz.core.entity.order.OrderInfoRetry;
import org.iteam.xlz.core.service.order.OrderInfoService;
import org.iteam.xlz.core.service.order.RefundService;

@SuppressWarnings("unchecked")
@Results({@Result(name="INDEX",type="freemarker",location="/WEB-INF/content/order/refund/index.html"),
    @Result(name="EDIT",type="freemarker",location="/WEB-INF/content/order/refund/edit.html")})
public class RefundAction extends AbstractModuleAction<OrderInfoRetry>{

	/**
	 * 
	 */
	private static final long serialVersionUID = 5057407075322773426L;
	private final String PATH="/order/refund";
	
	@Override
	public OrderInfoRetry getModel() {
		if(null==model){
			model=new OrderInfoRetry();
		}
		return model;
	}
	
	@Action(PATH+"/index")
	public String index(){
		return INDEX;
	}
	
	
	@Action(PATH+"/query")
	public String query(){
		map.put("total",RefundService.getInstance().counts());
		map.put("rows",RefundService.getInstance().query(page,rows));
		return MAP;
	}
	
	@Action(PATH+"/new")
	public String editNew(){
		super.object=OrderInfoService.getInstance().findOne(_id);
		return EDIT;
	}
	
	@Action(PATH+"/validate")
	public void yesyes(){
		print(OrderInfoService.getInstance().validate(model.getOid()));
	}
	
	@Action(PATH+"/create")
	public String create(){
		model.setCreator(ShiroUtil.currentAccount());
		boolean flag=RefundService.getInstance().create(model);
		map.put("state",flag);
		if(!flag){
			map.put("info","操作失败");
		}
		return MAP;
	}
	
	@Action(PATH+"/confirm")
	public String confirm(){
		model.setOperator(ShiroUtil.currentAccount());
		map.put("state",RefundService.getInstance().confirm(model));
		return MAP;
	}

}
